package com.iflytek.aisol.audit.iflytek.strategy.manage.mapper;


import cn.hutool.core.bean.BeanUtil;
import com.iflytek.aisol.audit.iflytek.strategy.manage.entity.ChannelConfig;
import com.iflytek.aisol.audit.iflytek.strategy.manage.entity.EngineParam;
import com.iflytek.aisol.audit.iflytek.strategy.manage.entity.ServerInstance;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * CLassName: ServiceMapper
 * Description:
 * Author: wuzhixiang
 * Date: 2024-12-28 16:08
 * Version: 1.0
 */
@Repository
public interface ServiceConfigMapper extends JpaRepository<ServerInstance, Long> {

    // 根据查询条件动态构建查询方法
    @Query("SELECT si FROM ServerInstance si WHERE (:instanceId IS NULL OR si.instanceId = :instanceId) " +
            "AND (:version IS NULL OR si.version = :version) " +
            "AND (:deleted IS NULL OR si.deleted = :deleted)")
    Page<ServerInstance> findAllWithFilters(
            @Param("instanceId") String instanceId,
            @Param("version") Long version,
            @Param("deleted") Long deleted,
            Pageable pageable); // Pageable 用于分页查询

    @Query("SELECT s FROM ServerInstance s WHERE s.instanceId = :instanceId " +
            "AND s.deleted = 0 ORDER BY s.version DESC")
    List<ServerInstance> findWithInstanceIdAndNoDeleteAndVersionMax(@Param("instanceId")String instanceId);

}
